<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        <!-- Make this page use standard caching procedure when used as an iframe -->
        <meta http-equiv="Cache-control" content="no-store, must-revalidate" />
        
        <title>Splash Page Testing</title>
        
        <script src="/js/greyspots.js" type="text/javascript"></script>
        <link href="/css/greyspots.css" type="text/css" rel="stylesheet" />
        
        <script>
            /* global: document */
            function ajaxCheckJSONResponseForError(request) {
                if (request.responseJSON) {
                    if (request.responseJSON.stat === false) {
                        return true;
                    }
                } else {
                    return true;
                }
                
                return false;
            }
            
            function ajaxNormalizeError (request) {
                var response = request.response, jsnTemp, jsnRet = {
                    'error_title': '',
                    'error_hint': '',
                    'error_text': '',
                    'error_file': '',
                    'error_context': '',
                    'original_response': response
                };
                
                // get error title and error hint
                if (request.bolFrontEndTimeout === true) {
                    jsnRet.error_text = 'Front-end Timeout Reached';
                    jsnRet.error_title = 'Front-end Timeout Reached';
                    jsnRet.error_hint = 'This request took too long. Please report this to a system administrator.';
                    
                } else if (response.status === 403) {
                    jsnRet.error_title = '403 Link Is Forbidden';
                    jsnRet.error_hint = 'You have no permission to use this link. If you need this link contact a system administrator and request permission for this link.';
                    
                } else if (response.status === 404) {
                    jsnRet.error_title = '404 Link Could Not Be Found';
                    jsnRet.error_hint = 'This link does not exist. Please report this to a system administrator.';
                    
                } else if (response.status === 408) {
                    jsnRet.error_title = '408 Request Took Too Long';
                    jsnRet.error_hint = 'This link is broken. Please report this to a system administrator.';
                    
                } else if (response.status === 500) {
                    jsnRet.error_title = '500 Internal Server Error';
                    jsnRet.error_hint = 'This call to the server failed. Please report this to a system administrator.';
                    
                } else if (response.status === 502) {
                    jsnRet.error_title = '502 Bad Gateway';
                    jsnRet.error_hint = 'This link is broken. Please report this to a system administrator.';
                    
                } else if (response.status === 504) {
                    jsnRet.error_title = '504 Gateway Timeout';
                    jsnRet.error_hint = 'This link is broken. Please report this to a system administrator.';
                }
                
                // get error text
                try {
                    jsnTemp = JSON.parse(response.responseText || response).dat;
                    
                    jsnRet.error_text = jsnTemp.error;
                    jsnRet.error_file = jsnTemp.filename;
                    jsnRet.error_context = jsnTemp.context;
                    
                    if (!jsnRet.error_text) {
                        jsnRet.error_text = JSON.parse(response.responseText || response).dat;
                    }
                } catch (err) {
                    if (response) {
                        jsnRet.error_text = response.responseText || JSON.stringify(response);
                    } else {
                        jsnRet.error_text = jsnRet.error_text || response;
                    }
                }
                
                jsnRet.error_file = jsnRet.error_file || '';
                
                return jsnRet;
            }
            
            function ajaxJSON(strLink, strParams, callback, intTimeout) {
                var request = new XMLHttpRequest();
                
                callback = callback || function () {};
                
                request.onreadystatechange = function() {
                    var normalizedError;
                    
                    // if expired cookie: go to login page
                    if (request.readyState === 4) {
                        try {
                            request.responseJSON = JSON.parse(request.responseText || request.response);
                        } catch (e) {
                            //throw e;
                        }
                        
                        if (!ajaxCheckJSONResponseForError(request)) {
                            callback(request.responseJSON);
                            
                        } else {
                            normalizedError = ajaxNormalizeError(request);
                            
                            // if session error: have the user log back in and refresh
                            if ((normalizedError.error_text.indexOf('Session expired') === 0 ||
                                normalizedError.error_text.indexOf('No Cookie') !== -1 ||
                                normalizedError.error_text.indexOf('requires you to login') !== -1) &&
                                strLink.indexOf('action_info') === -1) {
                                GS.normalUserLogin(function () {
                                    window.location.reload();
                                }, '', request.responseJSON.dat.default_subdomain);
                                
                            // else: callback with normalized error
                            } else {
                                callback(normalizedError, 'error');
                            }
                        }
                    }
                };
                
                request.open('GET', strLink, true);
                request.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');
                request.send(strParams);
                
                // if intTimeout has been set: start a timer to abort
                if (typeof intTimeout === 'number') {
                    if (request && request.readyState !== 4) {
                        setTimeout(function() {
                            request.bolFrontEndTimeout = true;
                            request.abort();
                        }, intTimeout);
                    }
                }
                
                return request;
            };
            document.addEventListener('DOMContentLoaded', function () {
                'use strict';

                ajaxJSON('https://api.github.com/repos/workflowproducts/postage/issues/comments', '', function (data, error) {
                    if (!error) {
                        for (var i = 0, len = data.length; i < len; i += 1) {
                            var elem = document.createElement('div');
                            elem.innerText = '@' + data[i].user.login + ' commented on issue #' + ;
                            document.body.appendChild(elem);
                        }
                    } else {
                        GS.ajaxErrorDialog(data);
                    }
                });

            });
        </script>
        
        <style>
            
        </style>
    </head>
    <body>
        
    </body>
</html>